// miniprogram/pages/ShopAdmin/MyShop/MyShop.js
const db=wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    one_1:0,
    one_2:0,
    one_3:0,
    two_1:'',
    two_2:'',
    two_3:'',
    number:0
  },
  return:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  MyGoods:function(e){
    wx.navigateTo({
      url: "/pages/ShopAdmin/MyGoods/MyGoods",
    })
  },
  ChatBox:function(e){
    wx.navigateTo({
      url: "/pages/ShopAdmin/ChatBox/ChatBox",
    })
  },
  OrderManagement:function(e){
    wx.navigateTo({
      url: "/pages/ShopAdmin/OrderManagement/OrderManagement",
    })
  },
  EvaluationManagement:function(e){
    wx.navigateTo({
      url: "/pages/ShopAdmin/EvaluationManagement/EvaluationManagement",
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getEvaluate()
  },
  getEvaluate:function(){
    var that=this
    wx.cloud.callFunction({
      name: "login",
    }).then(res => {
      console.log(res.result.openid);
      db.collection('Evaluate').where({
        SellOpenid:res.result.openid
      }).get().then(res => {
        // res.data 包含该记录的数据
        console.log(res.data)
        var two_1='低'
        var two_2='低'
        var two_3='低'
        if(res.data.length!=0){
          var one_1=0
          var one_2=0
          var one_3=0
          for(let i=0;i<res.data.length;i++){
            one_1= one_1+res.data[i].one_1
            one_2= one_2+res.data[i].one_2
            one_3= one_3+res.data[i].one_3
          }
          if(res.data.length!=0){
            one_1=(one_1*1.0/res.data.length).toFixed(1)
            one_2=(one_2*1.0/res.data.length).toFixed(1)
            one_3=(one_3*1.0/res.data.length).toFixed(1)
          }
        
          if(one_1>3.5){
            two_1='高'
          }else if(one_1>2){
            two_1='中'
          }
          if(one_2>3.5){
            two_2='高'
          }else if(one_2>2){
            two_2='中'
          }
          if(one_3>3.5){
            two_3='高'
          }else if(one_3>2){
            two_3='中'
          }
          that.setData({
            one_1:one_1,
            one_2:one_2,
            one_3:one_3,
            two_1:two_1,
            two_2:two_2,
            two_3:two_3,
          })
        }
        that.setData({
          two_1:two_1,
          two_2:two_2,
          two_3:two_3,
        })
      })
      db.collection('Goods').where({
        _openid:res.result.openid
      }).get().then(res => {
        // res.data 包含该记录的数据
        console.log(res.data.length)
        that.setData({
          number:res.data.length
        })
      })
    }).catch(err => {
      console.log(err);
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})